#include <QVariant>
#include <QDebug>
#include <QMetaObject>
#include <QQueue>
#include "ConfigData.h"


#define CONFIG_ITEM(TYPE,ID) \
    ID = new TYPE; \
    ID->setObjectName(#ID); \
    ID->translatedName = tr(#ID);

#define CONFIG_ENUM(TYPE,ID) \
    ID = new ItemEnum; \
    ID->setObjectName(#ID); \
    ID->translatedName = tr(#ID); \
    ID->setMetaEnum(QMetaEnum::fromType<TYPE>());

#define CONFIG_FLAG(TYPE,ID) \
    ID = new ItemFlag; \
    ID->setObjectName(#ID); \
    ID->translatedName = tr(#ID); \
    ID->setMetaEnum(QMetaEnum::fromType<TYPE>());

#define CONFIG_DATA_MODEL(TYPE,ID) \
    ID = new TYPE; \
    ID->setObjectName(#ID); \
    ID->translatedName = tr(#ID);

static const char *cuw = nullptr; // clear Unused Warrings

ConfigData::ConfigData(QObject *parent) : ConfigDataModel(parent)
{
    // copy CONFIG from Datas.h
    CONFIG_ENUM(QLocale::Language, myLanguage)
    CONFIG_ENUM(PickMode, pickMode)
    CONFIG_ITEM(ItemStringList, disabledApps)
    CONFIG_ITEM(ItemString, updateURL)
    CONFIG_ITEM(ItemBool, autoStart)
    CONFIG_ITEM(ItemBool, checkUpdate)

    CONFIG_DATA_MODEL(UI, ui)
    CONFIG_DATA_MODEL(Translate, translate)
    //
    ensureItemRegisterd();
    this->setObjectName("general");
    this->translatedName = tr("general");
    //

    //system->setWidgetStyle(ItemEnum::ComboBox);
    pickMode->setWidgetStyle(ItemEnum::RadioButton);
    myLanguage->setWidgetStyle(ItemEnum::ComboBoxCompleted);

    // translate
    cuw = QT_TR_NOOP("userName");
    cuw = QT_TR_NOOP("height");
    cuw = QT_TR_NOOP("zoom");
    cuw = QT_TR_NOOP("isLogin");
    cuw = QT_TR_NOOP("system");
    cuw = QT_TR_NOOP("options");
    cuw = QT_TRANSLATE_NOOP("ItemFlag", "T1");
    cuw = QT_TRANSLATE_NOOP("ItemFlag", "T2");
    cuw = QT_TRANSLATE_NOOP("ItemFlag", "T3");

}


void ConfigData::resetSelf()
{
    myLanguage->set(QLocale().language());
    pickMode->set(PickMode::All);
    disabledApps->set(QStringList());
    updateURL->set("https://sss");

}


UI::UI(QObject *parent) : ConfigDataModel(parent)
{
    CONFIG_ITEM(ItemInt, floatButtonSize)
    CONFIG_ITEM(ItemInt, noteWindowWidth)
    CONFIG_ITEM(ItemInt, noteWindowEdge)
    CONFIG_ENUM(Direction, noteWindowDirection)
    CONFIG_ITEM(ItemInt, triangleWidth)
    CONFIG_ITEM(ItemInt, triangleHeight)
    CONFIG_ITEM(ItemBool, isPinning)

    CONFIG_ENUM(Theme, uiTheme)
    //
    ensureItemRegisterd();
    //
    cuw = QT_TR_NOOP("list");
    cuw = QT_TR_NOOP("textColor");

}

void UI::resetSelf()
{
    floatButtonSize->set(40);
    noteWindowWidth->set(500);
    noteWindowEdge->set(10);
    triangleWidth->set(15);
    triangleHeight->set(15);
    isPinning->set(false);
    uiTheme->set(Theme::Light);
}


Translate::Translate(QObject *parent) : ConfigDataModel(parent)
{
    CONFIG_FLAG(API, enabledAPIs)
    CONFIG_ITEM(ItemOption, primaryAPI)
    CONFIG_ENUM(OCR_LANG, OCRLang)
    CONFIG_ITEM(ItemBool, ignoreCRLF) // 换行
    CONFIG_ITEM(ItemInt, networkTimeout) // 毫秒，网络请求超时时间
    CONFIG_ITEM(ItemString, baiduTokenURL)
    CONFIG_ITEM(ItemShortcut, OCRTextShortcut)
    CONFIG_ITEM(ItemShortcut, OCRTranslateShortcut)
    CONFIG_ITEM(ItemShortcut, searchBarShortcut)

    primaryAPI->setItemFlag(enabledAPIs);

    //
    ensureItemRegisterd();
    //
}

void Translate::resetSelf()
{
    enabledAPIs->clearFlag();
    enabledAPIs->setFlag(API::Baidu, true);
    OCRLang->set(Translate::CHN_ENG);
    networkTimeout->set(4000);
    baiduTokenURL->set("???");
    OCRTextShortcut->set(true, QKeySequence(Qt::AltModifier + Qt::Key_Q));
    searchBarShortcut->set(true, QKeySequence(Qt::AltModifier + Qt::Key_W));

}

#undef CONFIG_ITEM
#undef CONFIG_ENUM
#undef CONFIG_FLAG



